home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
350_01
/
pcx_disp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-29
|
40KB
|
1,141 lines
/*
*************************************************************************
*
* PCX_DISP.C - PCX_LIB Library Image Display Functions
*
* Version: 1.00C
*
* History: 91/02/14 - Created
* 91/04/01 - Release 1.00A
* 91/04/03 - Fixed "segread" call.
* 91/04/07 - Release 1.00B
* 91/11/18 - Fixed "pcx_set_palette" for large memory model.
* 91/12/01 - Release 1.00C
*
* Compiler: Microsoft C V6.0
*
* Author: Ian Ashdown, P.Eng.
* byHeart Software
* 620 Ballantree Road
* West Vancouver, B.C.
* Canada V7S 1W3
* Tel. (604) 922-6148
* Fax. (604) 987-7621
*
* Copyright: Public Domain
*
*************************************************************************
*/
/*
*************************************************************************
*
* PORTABILITY NOTES
*
* 1. While this program is written in ANSI C, it uses a number of
* function calls that are specific to the Microsoft C V6.0 library.
* These are documented as follows for the purposes of porting this
* program to other compilers and/or processors:
*
* _ffree - "free" for small model / far data
* _fmalloc - "malloc" for small model / far data
* _fmemcpy - "memcpy" for small model / far data
* int86 - execute 80x86 interrupt routine
* int86x - execute 80x86 interrupt routine (far
* data)
* _remapallpalette - remap entire video display color palette
* _selectpalette - select CGA color palette
* outpw - output word to 80x86 I/O port
*
* 2. When porting this program to other processors, remember that words
* are stored by 80x86-based machines in the big-endian format. That
* is, the eight least significant bits (lower byte) are stored
* first, followed by the eight most significant bits (upper byte).
* If PCX-format files are transferred to little-endian machines
* (such as those based on 680x0 and Z8000 processors), the order of
* bytes within each word will have to be reversed before they can
* be interpreted. (This applies to the file header only, since the
* encoded image data and optional 256-color palette are stored as
* bytes.)
*
* 3. MS-DOS does not recognize the 720 x 348 graphics mode of the
* Hercules monochrome display adapter. Therefore, the constant
* PCX_HERC should never be passed as a video mode parameter to any
* BIOS service routine.
*
* The Microsoft C compiler includes a "video mode" parameter
* definition (_HERCMONO) that is defined as 0x08. This is a
* reserved MS-DOS video mode that is apparently used internally by
* the ROM BIOS. It can, however, be passed to the Microsoft C
* library function "_setvideomode" to force the Hercules display
* adapter into graphics mode.
*
* Most other MS-DOS C compilers offer similar library functions to
* force the Hercules monochrome display adapter into its 720 x 348
* graphics mode.
*
*************************************************************************
*/
/* INCLUDE FILES */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <malloc.h>
#include <graph.h>
#include "pcx_int.h"
/* FORWARD REFERENCES */
static BOOL pcx_read_init(PCX_WORKBLK *, int, int);
static BOOL pcx_read_extpal(PCX_WORKBLK *);
static BOOL pcx_read_header(PCX_WORKBLK *);
static BOOL pcx_read_line(PCX_WORKBLK *, unsigned char *, int);
static BOOL pcx_set_palette(PCX_PAL *, int);
static void pcx_cga_palette(PCX_PAL *, int);
static void pcx_put_cga(PCX_WORKBLK *, unsigned char _far *, int);
static void pcx_put_ega(PCX_WORKBLK *, unsigned char _far *, int);
static void pcx_put_herc(PCX_WORKBLK *, unsigned char _far *, int);
static void pcx_put_vga(PCX_WORKBLK *, unsigned char _far *, int);
/* GLOBALS */
/* PUBLIC FUNCTIONS */
/*
*************************************************************************
*
* PCX_READ - Read PCX Image File
*
* Purpose: To read and display a PCX-format image file.
*
* Setup: BOOL pcx_read
* (
* char *fname,
* int vmode,
* int page
* )
*
* Where: fname is a PCX image file name.
* vmode is the MS-DOS video mode. Valid values are:
*
* PCX_HERC - 720 x 348 Hercules monochrome
* 0x04 - 320 x 200 4-color CGA
* 0x05 - 320 x 200 4-color CGA (color burst off)
* 0x06 - 640 x 200 2-color CGA
* 0x0d - 320 x 200 16-color EGA/VGA
* 0x0e - 640 x 200 16-color EGA/VGA
* 0x0f - 640 x 350 2-color EGA/VGA
* 0x10 - 640 x 350 16-color EGA/VGA
* 0x11 - 640 x 480 2-color VGA
* 0x12 - 640 x 480 16-color VGA
* 0x13 - 320 x 200 256-color VGA
*
* page is the video display page number. Valid values are:
*
* Mode PCX_HERC - 0 or 1
* Mode 0x0d - 0 to 7
* Mode 0x0e - 0 to 3
* Mode 0x0f - 0 or 1
* Mode 0x10 - 0 or 1
* All Other - 0
*
* Return: TRUE if successful; otherwise FALSE.
*
* Note: The video display adapter must be in the appropriate mode
* and active page for the image to be displayed.
*
*************************************************************************
*/
BOOL pcx_read
(
char *fname,
int vmode,
int page
)
{
int bpline; /* Number of bytes per scan line */
int line_num; /* Scan line number */
int max_lines; /* Maximum number of scan lines */
unsigned char *linep; /* PCX scan line buffer pointer */
BOOL status = TRUE; /* Return status */
PCX_WORKBLK *wbp; /* PCX image file workblock pointer */
/* Open a PCX image file workblock */
if ((wbp = pcx_open(fname, FALSE)) == (PCX_WORKBLK *) NULL)
return (FALSE);
/* Initialize the workblock for reading */
if (pcx_read_init(wbp, vmode, page) == FALSE)
{
(void) pcx_close(wbp); /* Close the PCX workblock */
return (FALSE);
}
/* Calculate the image height */
max_lines = wbp->header.yul + wbp->header.ylr + 1;
/* Calculate number of bytes per line (for all color planes) */
bpline = wbp->header.bppscan * wbp->header.nplanes;
/* Allocate the PCX scan line buffer */
if ((linep = (unsigned char *) malloc(bpline)) != (unsigned char *)
NULL)
{
/* Set the file pointer to the beginning of the encoded image data */
if (status == TRUE)
if (fseek(wbp->fp, (long) (sizeof(PCX_HDR)), SEEK_SET) != 0)
status = FALSE;
/* Set the video display adapter color palette unless the PCX file */
/* is Version 3.0 (i.e. - PC Paintbrush Version 2.8 w/o palette) */
if (status == TRUE)
if (wbp->header.version != 3)
if (pcx_set_palette(wbp->palettep, vmode) == FALSE)
status = FALSE;
/* Read the image line by line